#ifndef RenderSystemGLES_h__
#define RenderSystemGLES_h__

#include "RenderSystem.h"
#include "ContextGL.h"
#include "../infLib/infLib.h"
#include "PVRTglesExt.h"
#include "RenderWorldLocal.h"


typedef inf::HashMapGeneric<RWndHandle,ContextGL*> ContextGLHash;

class RenderSystemGLES: public RenderSystem {
    friend class RenderWorldLocal;
public:
    RenderSystemGLES();
    ~RenderSystemGLES();

    void    Init(RWndHandle hWnd, const RInitParams& params, RRendererType type );
    void    Shutdown();
    bool    IsInitialized() const;

    RRendererType GetType() const;
    const glConfig& GetConfig() const;

    int         NumContexts() const;
    bool        CreateContext( RWndHandle hWnd, const RInitParams& params );
    void        ReleaseContext( RWndHandle hWnd );
    void        SelectContext( RWndHandle hWnd );
    RWndHandle  GetCurrentContext() const;
    void        MakeCurrentContext();

    bigInt_t    NumberFrame() const;
    void        BeginFrame( int windowWidth, int windowHeight );
    void        EndFrame( int *frontEndMsec = NULL, int *backEndMsec = NULL );
    void        PresentFrame();

    RenderWorld *	AllocRenderWorld();
    void            SetPrimaryWorld( RenderWorld* world );
    RenderWorld *   GetPrimaryWorld() const;

    void			TakeScreenshot( const char *fileName );
private:
    void        ReleaseAllContext();
    void        ReleaseAllRenderWorld();
    void        DefaultStatus();
    void        SetupConfig();

    ContextGLHash contexts;

    ContextGL*      currentContext;
    RWndHandle      hWndHandle;

    inf::List<RenderWorldLocal*> worlds;
    RenderWorldLocal*	    primaryWorld;

    RRendererType   type;

    glConfig        config;
    bigInt_t        frameCounter;

    bool            initalized;

    CPVRTglesExt    glExt;
};

extern RenderSystemGLES tr;

#endif // RenderSystemGLES_h__